package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;


    @RequestMapping("/list")
   public Object query(@ModelAttribute("qo") StrategyCatalogQueryObject qo, Model m){
        qo.setOrderBy("sc.strategy_id,sc.sequence");
        m.addAttribute("pageInfo",strategyCatalogService.query(qo));
        return "/strategyCatalog/list";
    }

    @RequestMapping("/listAll")
    @ResponseBody
   public Object listAll(){
        return strategyService.listAll();
    }

    @RequestMapping("/listBystrategyId")
    @ResponseBody
   public Object listBystrategyId(Long strategyId){
        return strategyCatalogService.listByStrategyId(strategyId);
    }



    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(StrategyCatalog strategyCatalog){
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return "redirect:/strategyCatalog/list.do";
    }


}
